/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bpslrecognizer;

import java.io.IOException;
import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.CommonTreeNodeStream;

/**
 *
 * @author Holger
 */
public class Main {

    public static void main(String[] args) {
        
         try{
            ANTLRFileStream input = new ANTLRFileStream("observer.bpsl");
            SBPSL_3Lexer lexer = new SBPSL_3Lexer(input);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            SBPSL_3Parser parser = new SBPSL_3Parser( tokens );
            CommonTree tree = (CommonTree) parser.specification().getTree();
            System.out.println( "\nExtracted AST:\n" );
            System.out.println( tree.toStringTree() );
            
            CommonTreeNodeStream treeAsNodeStream = new CommonTreeNodeStream(tree);
            SBPSL_3_Walker_1 treewalker = new SBPSL_3_Walker_1(treeAsNodeStream);
            System.out.println( "\nFirst treatment of the AST specified with the tree grammar.\nRules checked:" );
            System.out.println( "--> A variable can be declared only once.\n" +
                                "--> A variable used in the formula has to be declared.\n" +
                                "--> A predicate has to be defined on the domain of its arguments\n" );
            treewalker.specification();
        }
        catch(IOException e){
            e.printStackTrace();
        }
        catch(RecognitionException e){
            e.printStackTrace();
        }
           
    }

}
